package com.minimalist.lindi.controller;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.contracttemplate.LindiContractTemplateQueryVO;
import com.minimalist.common.entity.lindi.vo.contracttemplate.LindiContractTemplateVO;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import com.minimalist.lindi.service.LindiContractTemplateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 林地指标平台_合同模板控制器
 *
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标平台_合同模板管理")
@RequestMapping("/lindi/contractTemplate")
public class LindiContractTemplateController{

    @Autowired
    private LindiContractTemplateService service;

    @PostMapping("/addContractTemplate")
    @Operation(summary = "添加合同模板")
    public R<?> addContractTemplate(
            @RequestBody @Validated(Add.class)
            LindiContractTemplateVO contractTemplateVO){
        service.addContractTemplate(contractTemplateVO);
        return R.ok();
    }

    @DeleteMapping("/deleteContractTemplateByContractTemplateId")
    @Operation(summary = "删除合同模板 -> 根据合同模板ID删除")
    public R<?> deleteContractTemplateByContractTemplateId(
            @RequestParam("contractTemplateId")
            @NotNull(message = "合同模板ID不能为空")
            @Parameter(name = "contractTemplateId", required = true, description = "合同模板ID")
            Long contractTemplateId){
        service.deleteContractTemplateByContractTemplateId(contractTemplateId);
        return R.ok();
    }

    @PutMapping("/updateContractTemplateByContractTemplateId")
    @Operation(summary = "修改合同模板")
    public R<?> updateContractTemplateByContractTemplateId(
            @RequestBody @Validated(Update.class)
            LindiContractTemplateVO contractTemplateVO){
        service.updateContractTemplateByContractTemplateId(contractTemplateVO);
        return R.ok();
    }

    @GetMapping("/getPageContractTemplateList")
    @Operation(summary = "查询合同模板列表(分页)")
    public R<PageResp<LindiContractTemplateVO>> getPageContractTemplateList(
            @RequestBody LindiContractTemplateQueryVO queryVO){
        return R.ok(service.getPageContractTemplateList(queryVO));
    }

    @GetMapping("/getContractTemplateByContractTemplateId/{contractTemplateId}")
    @Operation(summary = "根据合同模板ID查询合同模板")
    public R<LindiContractTemplateVO> getContractTemplateByContractTemplateId(
            @PathVariable(value = "contractTemplateId")
            @NotNull(message = "合同模板ID不能为空")
            @Parameter(name = "contractTemplateId", description = "合同模板ID", required = true)
            Long contractTemplateId){
        return R.ok(service.getContractTemplateByContractTemplateId(contractTemplateId));
    }

    @PostMapping("/deleteContractTemplateFileByFileId")
    @Operation(summary = "删除合同模板文件 -> 根据合同模板文件ID删除")
    public R<?> deleteContractTemplateFileByFileId(
            @RequestParam("fileId") @NotNull(message = "合同模板文件ID不能为空")
            @Parameter(name = "fileId", required = true, description = "合同模板文件ID")
            Long fileId){
        service.deleteContractTemplateFileByFileId(fileId);
        return R.ok();
    }
}